﻿using System.Web.Mvc;
using System.Web.Routing;
using Inovout.Web.Mvc;
using Inovout.YunYao.Models;
using Inovout.YunYao.Services;
using Inovout.YunYao.Solutions.Web.Controllers;

namespace Inovout.YunYao.Solutions.Web
{
    public class MonitoringElementBinder : EntityModelBinder
    {
        public override object BindModel(ControllerContext controllerContext,ModelBindingContext bindingContext)
        {
            object model = base.BindModel(controllerContext, bindingContext);
            IMonitoringElement monitoringElement = model as IMonitoringElement;
            if (monitoringElement != null && monitoringElement.Solution == null)
            {
                //ISolutionService solutionService = ComponentRegistry.Resolve<ISolutionService>();
                //RouteData routeData = RouteTable.Routes.GetRouteData(controllerContext.HttpContext);
                //monitoringElement.Solution = solutionService.FindByCode(int.Parse(routeData.Values["solution"].ToString()));
                monitoringElement.Solution = ((IMonitoringElementController)controllerContext.Controller).Solution;

            }
            return model;
        }
    }
}